<?php 

/**
 * 个人中心控制器
 */
class SearchController extends CommonController{
	
	
	//订单
	public function index(){
//		p($_SESSION);
//		cart::delAll();
		//获得顶级分类
		$cateData =K('Cate')->where("pid=0")->all();
		$this->assign("cateData",$cateData);
		
		//个人中心订单
		$uid = $_SESSION['uid'];
		
		$Gdata = M()->join('__user__ u JOIN __gorder__ o ON u.uid=o.user_uid JOIN __gorder_list__ ol ON o.oid=ol.gorder_oid JOIN __goods__ g ON ol.goods_gid=g.gid')->where("uid={$uid}")->all();
//		p($Gdata);
		$this->assign('Gdata',$Gdata);
		
		
		//头像
		$uid = $_SESSION['uid'];
		$info =M('user')->where("uid={$uid}")->find();
//		p($info);
		$this->assign("info",$info);
		
		
		
		
		$this->display();
	}
	
	//删除订单
	public function delOrder(){
	    $oid = Q('get.oid',0,'intval');
//		p($oid);die;
		//删除订单表数据
		M('gorder')->where("oid={$oid}")->delete();
		//删除订单列表数据
		M('gorder_list')->where("olid={$oid}")->delete();
		$this->success('删除订单成功');
	}
	
	
	//地址
	public function addRess(){
		
//		//获得顶级分类
		$cateData =K('Cate')->where("pid=0")->all();
		$this->assign("cateData",$cateData);
		
		
		//循环地址管理
		$uid = $_SESSION['uid'];
//		p($uid);
		$addRess =M('Address')->where("user_uid={$uid}")->all();
//		p($addRess);
		$this->assign('addRess',$addRess);
		
		//头像
		$uid = $_SESSION['uid'];
		$info =M('user')->where("uid={$uid}")->find();
//		p($info);
		$this->assign("info",$info);
		
		
		$this->display();
	}
	
	
	/**
	 * 添加地址
	 */
	public function addResss(){
		
//		p($_POST);
		if(IS_POST){
			$_POST['address'] = $_POST['province'].'&nbsp;'.$_POST['city'].'&nbsp;'.$_POST['county'].$_POST['content'];
			$_POST['user_uid'] = $_SESSION['uid'];
			$model = K('Address');
			if(!$model->addDate()){
				$this->error($model->error);
			}
			$this->success('添加成功');
		}
	}
	
	//删除地址
	public function addressDel(){
		$adid = $_GET['adid'];
		$addressDel =M('Address')->where("adid={$adid}")->delete();
		$this->success('删除成功');
	}
	
	
	//编辑地址
//	public function editeaddResss(){
//		$adid = $_GET['adid'];
//		$model = K('Address');
//		$oldData = $model->where("adid={$adid}")->find();
//		p($oldData);
////		$this->success('编辑成功');
//	}
	
	
	
	//基本信息
	public function personal(){
		
//		//获得顶级分类
		$cateData =K('Cate')->where("pid=0")->all();
		$this->assign("cateData",$cateData);
		
		
		//头像
		$uid = $_SESSION['uid'];
		$info =M('user')->where("uid={$uid}")->find();
//		p($info);
		$this->assign("info",$info);
		
		
		$this->display();
	}
	
	//修改头像
	public function alter(){
		if(IS_POST){
			$model = K('Face');
			if(!$model->addData()){
				$this->error($model->error);
			}
			
			$this->success('成功', U('index'));
		}
//		p($_FILES);
//		//获得顶级分类
		$cateData =K('Cate')->where("pid=0")->all();
		$this->assign("cateData",$cateData);
		
		
		//头像
		$uid = $_SESSION['uid'];
		$info =M('user')->where("uid={$uid}")->find();
//		p($info);
		$this->assign("info",$info);
		$this->display();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}














 ?>